{% load shorturl %}
{% load ordering %}
<div class="item" id="{{ item.id }}" style="opacity:{{ item.opacity }}">
    <div class="item_control">
    <div class="item_image">
        {% if chapter %}
            <a href="{% url item_filter chapter item.slug %}">
        {% else %}
            <a href="{{ item.get_absolute_url }}">
        {% endif %}
            {% with image=item.get_small_image %}
                {% if image %}
                    <img src="{{ image }}"/>
                {% else %}
                    <img src="{{ STATIC_URL }}images/blank.png"/>
                {% endif %}
            {% endwith %}
        </a>
    </div>
    <div class="item_body">
        <input type="hidden" name="airtime_current" class="airtime_current"
               value="{{ item.airtime_left }}">
        <div class="item_message">
            <div class="message">
                {% if chapter %}
                    <a href="{% url item_filter chapter item.slug %}">
                {% else %}
                    <a href="{{ item.get_absolute_url }}">
                {% endif %}
                    {{ item.message }}
                </a>
            </div>
            {% if item.created_by != user %}
                <div class="follow">
                    {% if user.is_authenticated %}
                        <a class="follow_link right" id="follow_link_{{ item.id }}"
                           href="#follow_user{{ item.id }}">
                            {%  with is_following=user|args:item.created_by|call:"is_following"  %}
                                {% if is_following %}
                                    You follow {{ item.created_by }}
                                {% else %}
                                    Follow {{ item.created_by }}
                                {% endif %}
                            {% endwith %}
                        </a>
                    {% else %}
                        <a class="auth_required right" href="#">
                            Follow {{ item.created_by }}
                        </a>
                    {%  endif %}
                </div>
                {% if user.is_authenticated %}
                    {% include "follow_popup.html" with follow_user=item.created_by %}
                {% endif %}
            {% endif %}
            <div class="bottom_line">
                {% with time_left=item.time_expired|timeuntil %}
                    {% if time_left == '0 minutes'%}
                        {% if item.slumped %}
                                <span class="gray">OFFLINE</span>
                        {% else %}
                            <span>less than 1 minute left</span>
                        {% endif %}
                    {% else %}
                        <span>{{ time_left }} left</span>
                    {% endif %}
                {%  endwith %}
                &nbsp;<strong>&bull;</strong>&nbsp;
                {% with count=item.actions_total_visitors %}
                    {% if count %}
                        <a class="responses" href="#responses{{ item.id }}">
                            View {{ count }} response{% if count > 1 %}s{% endif %}
                        </a>
                        <span class="hidden"><div class="triangle_blue"></div></span>
                    {% else %}
                        {% if not item.slumped %}
                            {% if user.is_authenticated %}
                                <a class="comments" href="#comments{{ item.id }}">
                            {% else %}
                                <a class="auth_required right" href="/">
                            {% endif %}
                        Add your comment</a>
                        {% endif %}
                    {% endif %}
                {% endwith %}
                {% if not item.slumped and item.created_by == user %}
                    &nbsp;<strong>&bull;</strong>&nbsp;
                    {% if item.airtime_left %}
                        <a class="airtime" href="#airtime{{ item.id }}">
                            Airtime+</a>
                    {% else %}
                        <span class="gray">Airtime</span>
                    {%  endif %}
                {% endif %}
            </div>
        </div>
        <div class="user_actions_container">
            <div class="progressbar">
                {% with ies=item.item_ies_ranges %}
                    {% for i in ies|first %}
                        <span class="blue_bull">&bull;</span>
                    {% endfor %}
                    {% for i in ies|last %}
                        <span class="gray_bull">&bull;</span>
                    {% endfor %}
                {% endwith %}
            </div>
            <div class="user_actions">
                {% if not item.slumped %}
                    <div>
                        {% if user.is_authenticated %}
                            <a class="comments" href="#comments{{ item.id }}">Comment</a>
                        {% else %}
                            <a class="auth_required" href="/">Comment</a>
                        {% endif %}
                    </div>
                    <div>
                        {% if user.is_authenticated %}
                            {% if user in item.users_like_it %}
                                <span class="gray">You liked it</span>
                            {% else %}
                                <form class="like_form" id="like_form{{ item.id }}"
                                      method="POST" action="/item/like/">
                                    {% csrf_token %}
                                    <input type="hidden" name="item" value="{{ item.id }}">
                                    {% if profile_user %}
                                        <input type="hidden" name="profile" value="{{ profile_user.id }}">
                                    {% endif %}
                                    <input type="submit" class="button_as_link" value="Like">
                                </form>
                            {% endif %}
                        {% else %}
                            <a class="auth_required" href="/">Like</a>
                        {% endif %}
                    </div>
                    <div>
                        {% if user.is_authenticated %}
                            <a class="share" href="#share{{ item.id }}">Share</a>
                        {% else %}
                            <a class="auth_required" href="/">Share</a>
                        {%  endif %}
                    </div>
                {% endif %}
                {% if profile_user == user %}
                    <div>
                        <form class="delete_form" id="delete_form{{ item.id }}"
                              method="POST" action="/item/delete/">
                            {% csrf_token %}
                            <input type="hidden" name="item" value="{{ item.id }}">
                            <input type="submit" class="button_as_link" value="Delete">
                        </form>
                    </div>
                    {% if profile_user.is_elite and item.slumped and not item.is_reposted %}
                        <div>
                            <form class="repost_form" id="repost_form{{ item.id }}"
                                  method="POST" action="/item/repost/">
                                {% csrf_token %}
                                <input type="hidden" name="id" value="{{ item.id }}">
                                <input type="submit" class="button_as_link" value="Re-post">
                            </form>
                        </div>
                    {% endif %}
                {% endif %}
            </div>
        </div>

        {% if item.created_by == user and not item.slumped %}
            <div class="airtime_div hidden_actions" id="airtime{{ item.id }}">
                <form class="airtime_form" id="airtime_form{{ item.id }}" method="POST" action="/item/airtime/">
                    {% csrf_token %}
                    <input type="hidden" name="item" value="{{ item.id }}">
                    {% if profile_user %}
                        <input type="hidden" name="profile" value="{{ profile_user.id }}">
                    {% endif %}
                    {% with airtime_left=item.airtime_left %}
                        <input type="hidden" name="count" class="airtime_count"
                           value="{% if airtime_left > 0 %}1{% else %}0{% endif %}">
                        <div class="add">Add&nbsp;</div>
                        <div class=counter>
                            <div class="btn_less"></div>
                            <div class="airtime_amount">{% if airtime_left > 0 %}1{% else %}0{% endif %}</div>
                            <div class="btn_more"></div>
                            <div class="to_this_item">&nbsp;airtime to this item</div>
                        </div>
                        <input type="submit" class="submit_button airtime_button"
                               value="Add" {% if airtime_left == 0 %}disabled="1"{% endif %}>
                    {% endwith %}
                </form>
            </div>
        {% endif %}

        <div class="comment_div hidden_actions" id="comments{{ item.id }}">
            {% if not item.slumped and  user.is_authenticated %}
                <form class="comment_form" id="comment_form{{ item.id }}" method="POST" action="/comment/submit/">
                    {% csrf_token %}
                    <input type="hidden" name="item" value="{{ item.id }}">
                    <input type="text" name="comment" class="comment_text" placeholder="Write a comment...">
                    {% if profile_user %}
                        <input type="hidden" name="profile" value="{{ profile_user.id }}">
                    {% endif %}
                    {% if user.is_authenticated %}
                        <input type="submit" class="submit_button comment_button" value="Comment">
                    {% else %}
                        <input type="submit" class="submit_button comment_button auth_required"
                               value="Comment" disabled="1">
                    {% endif %}
                </form>
            {%  endif %}
            <div class="responses" id="responses{{ item.id }}">
                {% include "responses.html" %}
            </div>
        </div>
        {% if user.is_authenticated %}
            {% if not item.slumped %}
            <div class="share_div hidden_actions" id="share{{ item.id }}">
                {% if user.get_facebook_token %}
                    <a class="facebook_share share_picture" id="facebook_share_{{ item.id }}"
                       href="#facebook{{ item.id }}">
                {% else %}
                    <a class="share_picture" id="facebook_share_{{ item.id }}"
                    href="/associate/facebook/?next={% url share_open 'facebook' item.id %}" target="_blank">
                {% endif %}
                        <span class="icon_facebook"></span>
                        <span class="share_label">Share</span>
                    </a>
                {% if user.get_twitter_tokens %}
                    <a class="twitter_tweet share_picture" id="twitter_share_{{ item.id }}"
                     href="#twitter{{ item.id }}">
                {% else %}
                    <a class="share_picture" id="twitter_share_{{ item.id }}"
                    href="/associate/twitter/?next={% url share_open 'twitter' item.id %}" target="_blank">
                {% endif %}
                        <span class="icon_twitter"></span>
                        <span class="share_label">Tweet</span>
                    </a>
                <a href="mailto:?subject=Just went live! {{ item.message }}&amp;body=Check out this story on 8minut.es: {{ item.message }}%0A%0A{% shorturl item %}" target="_blank" title="[GMCP] Compose a new mail to " onclick="window.open('https://mail.google.com/mail/?view=cm&amp;fs=1&amp;tf=1&amp;to=&amp;su=Just%20went%20live!%20{{ item.message }}&amp;body=Check%20out%20this%20story%20on%208minut.es:%20{{ item.message }}%0A{% shorturl item %}%0A%0AHurry%20Up!%20Time%20is%20running%20out%20on%20this%20item','Compose new message','width=640,height=480');return false" rel="noreferrer">
                    <span class="icon_email"></span>
                    <span class="share_label">Email</span>
                </a>
                {% include "facebook_share.html" %}
                {% include "twitter_share.html" %}
            </div>
            {%  endif %}
        {% endif %}
    </div>
    <div class="clearfix"></div>
    </div>
</div>
